﻿package nl.sanity.puremvc.model 
{
	import flash.display.LoaderInfo;
	
	import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;
	
	import nl.sanity.debug.LogConsole;

	/**
	 * FlashVarsProxy
	 * Keeps track of any variables that were sent to the Flash app. within the HTML, e.g. via SWFObject
	 * 
	 * @langversion ActionScript 3
	 *
	 * @author A. Gosman
	 * @since  28/03/2009
	 */
    public class FlashVarsProxy extends Proxy implements IProxy
    {
		public static const NAME	: String = "FlashVarsProxy";
		
		private var _vars			: Object;

		// --- CONSTRUCTOR ----------------------------------------

		public function FlashVarsProxy( loaderInfo:LoaderInfo )
        {
            super ( NAME );
			
			_vars = loaderInfo.parameters;
        }
		
		// --- PUBLIC FUNCTIONS ----------------------------------------

		/**
		 * Returns 	
		 * @param	key:String	The name of the parameter of which to return the value.
		 * @return	The value of the provided parameter as a String.
		 * 			If the parameter was not found, it returns null.
		 */
		public function getValue( key:String ):String
		{ 
			if ( _vars && _vars [ key ] )
			{
				return _vars [ key ];
			}
			else
			{
				LogConsole.warn ( "Parameter " + key + " was not found" );
				return null;
			}
		}
		
		
	}
}